<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "show".
 *
 * @property integer $id
 * @property string $name
 * @property integer $state
 * @property integer $app_return
 * @property integer $img_small_id
 * @property integer $img_thumb_id
 * @property integer $img_url_id
 * @property integer $space_id
 * @property integer $top_time
 * @property integer $publish_uid
 * @property integer $publish_time
 * @property string $content
 */
class Show extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
	public $top_time_1,$QRcode;
    public static function tableName()
    {
        return 'show';
    }

    /**
     * @inheritdoc
     */
    public $image_upload;
    public function rules()
    {
        return [
            [['state', 'app_return', 'img_small_id', 'img_thumb_id', 'img_url_id', 'space_id', 'top_time', 'publish_uid', 'publish_time'], 'integer'],
            [['content','top_time_1'], 'string'],
            [['name'], 'string', 'max' => 64],
            [['name'],'required'],
            
            [['image_upload'], 'image','extensions' => 'png,jpg,jpeg,gif,bmp','maxWidth'=>'2000','maxHeight'=>'2000',
            'overWidth'=>'宽必须低于2000像素','overHeight'=>'高必须低于2000像素'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => Yii::t('app','Show Name'),
            'state' =>  Yii::t('app','Show State'),
            'app_return' =>  Yii::t('app','Show App Return'),
            'img_small_id' => Yii::t('app', 'Show Small Image'),
            'img_thumb_id' => Yii::t('app', 'Show Thumb Image'),
            'img_url_id' => Yii::t('app', 'Show Url Image'),
            'space_id' =>  Yii::t('app','Show Space ID'),
            'top_time' =>  Yii::t('app','Show Top Time'),
            'publish_uid' => Yii::t('app', 'Show Publish Uid'),
            'publish_time' =>  Yii::t('app','Show Publish Time'),
            'content' =>  Yii::t('app','Show Content'),
            'image_upload' => Yii::t('app', 'Show Image'),
        ];
    }
    /**
     * 生成二维码
     * @param unknown $id
     */
    public static function generateQRcode($id){
        $url = 'https://www.jajahome.com/gjj/frontend/web/show-home/show-home-item?show_id='.$id;
    	$QRcode = Qr::generate_admin($url,'show');	 
    	Yii::$app->db->createCommand()->update('show', ['qrcode'=>$QRcode],"id={$id}")->execute();
    }
}
